package com.yuanduo_app.manager;

import com.xujl.fastlib.utils.SpHelper;
import com.xujl.fastlib.utils.StringUtils;

import com.yuanduo_app.consts.SpName;
import com.yuanduo_app.entity.UserInfoEntity;

public class CacheManager {
    private UserInfoEntity mUserInfoEntity = new UserInfoEntity();
    private String token;


    public static CacheManager getInstance () {
        return Holder.INSTANCE;
    }

    private CacheManager () {
    }


    public boolean isLogin () {
        return !StringUtils.isEmpty(token);
    }

    private static class Holder {
        private static final CacheManager INSTANCE = new CacheManager();
    }

    public void init () {
        UserInfoEntity entity = SpHelper.getInstance().getObject(SpName.USER_INFO);
        if (entity != null) {
            mUserInfoEntity = entity;
        }
        this.token = SpHelper.getInstance().getString(SpName.TOKEN);
    }


    public UserInfoEntity getUserInfoEntity () {
        return mUserInfoEntity;
    }

    public void setUserInfoEntity (UserInfoEntity userInfoEntity) {
        mUserInfoEntity = userInfoEntity;
    }

    public String getToken () {
        return token;
    }

    public void setToken (String token) {
        this.token = token;
    }
}
